home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 460_01 / YACL0160.ZIP / uidemo / window / main.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-20  |  3.1 KB  |  145 lines

  1.  
  2.  
  3. // A window demo using YACL
  4.  
  5.  
  6. #include "ui/composit.h"
  7. #include "ui/applic.h"
  8. #include "ui/label.h"
  9. #include "ui/pushbtn.h"
  10. #include "ui/stddlg.h"
  11.  
  12.  
  13. // ======================== Class AppWindow ===========================
  14.  
  15.  
  16. #define ID_LABEL1 11
  17. #define ID_LABEL2 12
  18. #define ID_LABEL3 13
  19. #define ID_LABEL4 14
  20. #define ID_LABEL5 15
  21. #define ID_BUTTON 16
  22.  
  23.  
  24. UI_ViewDescriptor desc[] = {
  25.     {View_Label,      ID_LABEL1, 15,  15, 320, 20, FALSE,  ""},
  26.     {View_Label,      ID_LABEL2, 15,  40, 320, 20, FALSE,  ""},
  27.     {View_Label,      ID_LABEL3, 15,  65, 320, 20, FALSE,  ""},
  28.     {View_Label,      ID_LABEL4, 15,  90, 320, 20, FALSE,  ""},
  29.     {View_Label,      ID_LABEL5, 15, 120, 320, 20, FALSE,  ""},
  30.     {View_PushButton, ID_BUTTON,125, 170,  80, 40, FALSE,  ""},
  31.     {View_None, 0}
  32. };
  33.  
  34. class AppWindow: public UI_CompositeVObject {
  35.  
  36. public:
  37.     AppWindow ();
  38.  
  39. protected:
  40.  
  41.     void Initialize  ();
  42.  
  43.     bool Iconify ();
  44.  
  45.     bool Deiconify ();
  46.     
  47.     bool Reconfigure (const UI_Rectangle& r);
  48.  
  49.     bool HandleChildEvent (const UI_Event& e);
  50.  
  51. private:
  52.     void SetLabels ();
  53.     long _xInc, _yInc;
  54.     short _count;
  55. };
  56.  
  57.     
  58. AppWindow::AppWindow()
  59. : UI_CompositeVObject (NULL, desc, FALSE, UI_Rectangle (200, 200, 350, 230))
  60. {
  61.     _xInc = _yInc = 32;
  62.     _title = "YACL Window Demo";
  63.     (*this)[ID_LABEL1]->Title() = "I am a window.";
  64.     (*this)[ID_BUTTON]->Title() = "Move!";
  65.     _count = 0;
  66. }
  67.  
  68. void AppWindow::Initialize ()
  69. {
  70.     SetLabels ();
  71. }
  72.  
  73.  
  74.  
  75. bool AppWindow::Reconfigure (const UI_Rectangle& r)
  76. {
  77.     UI_CompositeVObject::Reconfigure (r);
  78.     SetLabels();
  79.     return TRUE;
  80. }
  81.  
  82. void AppWindow::SetLabels ()
  83. {
  84.     UI_Rectangle r = Shape();
  85.     (*this)[ID_LABEL2]->Title() =
  86.         "My client area is at (" + CL_String (r.Left())
  87.         + ", " + CL_String (r.Top()) + ").";
  88.     (*this)[ID_LABEL3]->Title() =
  89.         "My client area size is " + CL_String (r.Width ())
  90.         + " x " + CL_String (r.Height ()) + ".";
  91.     UI_Rectangle rect = WindowShape ();
  92.     (*this)[ID_LABEL4]->Title() =
  93.         "My window area size is " + CL_String (rect.Width ())
  94.         + " x " + CL_String (rect.Height ()) + ".";
  95.     (*this)[ID_LABEL5]->Title() = "I had been iconified " + CL_String
  96.         (_count) + " times.";
  97. }
  98.  
  99.  
  100.  
  101. bool AppWindow::HandleChildEvent (const UI_Event& e)
  102. {
  103.     if (e.Origin()->ViewID() != ID_BUTTON || e.Type() != Event_Select)
  104.         return FALSE;
  105.  
  106.     UI_Rectangle screen_rect = _Application->ScreenRect();
  107.     UI_Rectangle& client_area = Shape();
  108.     long x = client_area.Origin().XCoord();
  109.     long y = client_area.Origin().YCoord();
  110.     if (x >= screen_rect.Width() - client_area.Width() || x < 0)
  111.         _xInc = -_xInc;
  112.     if (y >= screen_rect.Height() - client_area.Height() || y <= 20)
  113.         _yInc = -_yInc;
  114.     client_area += UI_Point (_xInc, _yInc); // Move the window
  115.     return TRUE;
  116. }
  117.  
  118. bool AppWindow::Iconify ()
  119. {
  120.     _count++;
  121.     return TRUE;
  122. }
  123.  
  124.  
  125. bool AppWindow::Deiconify ()
  126. {
  127.     (*this)[ID_LABEL5]->Title() = "I have been iconified " + CL_String
  128.         (_count) + " times.";
  129.     return TRUE;
  130. }
  131.  
  132.  
  133.  
  134. // ======================== Main program ===========================
  135.  
  136.  
  137. int UI_Application::Main (int, char* []) 
  138. {
  139.     MakeTopWindow (new AppWindow);
  140.     Run();
  141.     return 0;
  142. }
  143.  
  144.  
  145.